package com.wenju.inappupdate;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.wenju.inappupdatemodule.bean.UpdateEntity;
import com.wenju.inappupdatemodule.net.UpdateAgent;
import com.wenju.inappupdatemodule.utils.UpdateHelper;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Button btn_check = findViewById(R.id.check);
        btn_check.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateEntity updateEntity = new UpdateEntity();
                updateEntity.setAppName(getString(R.string.app_name));
                updateEntity.setContent(getString(R.string.dialog_context));
                updateEntity.setUpdateUrl("App下载地址");
//                updateEntity.setVersionCode(6);
//                updateEntity.setVersionName("6.0");


                UpdateAgent.getInstance().showAlertDialog(MainActivity.this,updateEntity,false);
                //直接下载，可自定义弹窗
                //UpdateAgent.getInstance().downloadApp(MainActivity.this, updateEntity);
            }
        });

        UpdateAgent.setOnProgressChangedListener(new UpdateAgent.onProgressChangedListener() {
            @Override
            public void onProgressChangedListenerChanged(int currentProgress) {
                Log.d("下载进度-------》",currentProgress+"");
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        UpdateHelper
                .getInstance()
                .showProgressDialog(true)
                .setDownType(UpdateHelper.DownType.down_click_Install);
//                .setmNoUpdateDialogTitle(getString(R.string.no_update_dialog_title))
//                .setmNoUpdateDialogContext(getString(R.string.no_update_dialog_context))
//                .setmNoUpdateDialogConfirm(getString(R.string.no_update_dialog_confirm))
//                .setmNewUpdateTitle(getString(R.string.new_update_title))
//                .setmNewUpdatePositiveButton(getString(R.string.new_update_positive_button))
//                .setmNewUpdateNegativeButton(getString(R.string.new_update_negative_button))
//                .setmDwonProgressDialogTitle(getString(R.string.dwon_progress_dialog_title))
//                .setmDownProgressDialogNegativeButton(getString(R.string.down_progress_dialog_negative_button))
//                .setmDownProgressDialogPositiveButton(getString(R.string.down_progress_dialog_positive_button))
//                .setmContinuouslyOpenServicePrompts(getString(R.string.continuously_open_service_prompts))
//                .setmDownFail(getString(R.string.down_fail))
//                .setmDownSuccess(getString(R.string.down_success))
//                .setmDownSuccessToast(getString(R.string.down_success_toast))
//                .setmDownStop(getString(R.string.down_stop))
//                .setmNotificationName(getString(R.string.notification_name))
//                .setmBuilderTicker(getString(R.string.builder_ticker))
//                .setmBuilderContext(getString(R.string.builder_context))
//                .setmNotificationId(getString(R.string.notification_id))
//                .setmNotificationChannelId(getString(R.string.notification_channel_id));
    }
}
